/** File Description
 *
 * Copyright (C) 2009 Ismail SEZEN
 * This is header file of Windbull.c file.
 * -------------------------------------------------------------------------------------------
 * This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * -------------------------------------------------------------------------------------------
 * Project Name: Windbull
 * Files(4) : Windbull.c, Windbull.h, WindbullParser.c, WindbullParser.h
 * AUTHOR: Ismail SEZEN
 * e-mail: sezenismail@gmail.com
 * 13-05-2009 [12:20]
 * -------------------------------------------------------------------------------------------
 * Created by Code:Blocks 8.02
 */

extern char  WB_Direction_to_string[17][5];
/** Variables */
//{
extern int WB_Total_Data_Count ;
extern float *WB_arr_speed;
extern int *WB_arr_direction ;
extern float WB_height;
extern float WB_z0;
//
extern int WB_histo_class_count;
extern int WB_histo_bin_value;
extern double *WB_histo_ui;
extern int *WB_histo_mi;
extern double *WB_histo_pui;
extern double *WB_histo_fui;
//
extern float WB_speed_max_var;
extern float WB_speed_min_var;
extern float WB_speed_avg_var;
extern float WB_speed_median_var;
extern float WB_speed_mode_var;
extern double WB_speed_sd_var;
extern double WB_speed_variance_var;
extern double WB_lambert_persistance_var;
extern double WB_autocorrelation_var;
extern double WB_energy_pattern_factor_var;
extern double WB_weibull_k_param_var;
extern double WB_weibull_c_param_var;
//}

/** Routines */
extern int WB_Initialize(char *fileName);
extern void WB_extrapolate_speed();
extern void WB_Finalize();
extern float WB_speed_max();
extern float WB_speed_min();
extern float WB_speed_avg();
extern float WB_speed_median();
extern float WB_speed_mode();
extern double WB_speed_sd();
extern double WB_speed_variance();
extern double WB_lambert_persistance();
extern double WB_autocorrelation();
extern double* WB_sd_hourly();
extern void WB_sd_monthly(double *p_array_12);
extern double* WB_variance_hourly();
extern void WB_variance_monthly(double *p_array_12);
extern void WB_variance_to_sd(double *p_array_variance_12, double *p_array_12,int length);
extern void WB_direction_frequencies();
extern void WB_speed_frequencies(double *p_frequency);
extern void WB_speed_histogram();
extern int WB_SDC(double **p_array_Ti, double **p_array_Wt);
extern double WB_energy_pattern_factor();
extern double WB_weibull_k_param();
extern double WB_weibull_c_param();
extern void WB_avg_hourly(double *p_arr_hourly_speed,  double (*operation)(float *, double *) );
extern void WB_avg_monthly(double *p_array_12, double (*operation)(float *, double *));
extern void WB_avg_monthly_day_night(double *avg_monthly_speed_day, double *avg_monthly_speed_night, double (*operation)(float *, double *));
extern void WB_avg_seasonal(double  *avg_sesonal_speed, double (*operation)(float *, double *));
extern void WB_lambert_persistance_hourly(float *p_array_24);
extern void WB_lambert_persistance_monthly(float *p_array_12);
extern void WB_lambert_persistance_seasonal(float *p_array_4);

//
extern float get_max_speed(float *p_speed,int length);
extern float get_min_speed(float *p_speed,int length);
extern float speed_median(float *p_speed,int length);
extern float speed_mode(float *p_speed,int length);
extern float speed_avg(float *p_speed,int length);
//
extern double standart_deviation(float *p_speed,int length);
extern void standart_deviation_hourly(float *p_speed, int length, double *p_sd_hourly);
extern double variance(float *p_speed, int length);
extern void variance_hourly(float *p_speed, int length, double *p_avg_hourly_variance);
extern double autocorelation(float *p_speed,int length,int offset);
//
extern double power_coefficient_length(float z0);
extern double power_coefficient_speed_and_height(float Uref, float Zref);
extern double power_coefficient_speed_and_length(float Uref, float Z0);
//
extern double extraplation_height(float Uref, float Zref, float Z,double a);
extern void extrapolate_speed(float *p_speed,int length, float Zref,float Z, float z0);
//
extern double wind_speed(float *value, double *height);
extern double wind_power(float *value, double *height);
extern double energy_pattern_factor(float*p_speed,int length);
extern void speed_frequency(float *p_speed,int length);
extern void wind_avg_hourly(float *p_speed,int length,double *hours,double *height,  double (*operation)(float *, double *) );
//extern void avg_speed_power_hourly(float * p_speed, int length, double *P,double height);
extern void Wind_avg_monthly(char *pData, int buffer_size, float *p_speed, int length,double *avg_monthly_speed,double *height,  double (*operation)(float *, double *));
extern void Wind_avg_seasonal(char *pData, int buffer_size, float *p_speed, int length,double *avg_monthly_speed,double *height,  double (*operation)(float *, double *));
extern void Wind_avg_monthly_day_night(char *pData, int buffer_size, float *p_speed, int length, double *avg_monthly_day, double *avg_monthly_night, double *height,
										double (*operation)(float *, double *));

extern double weibull_k_param(double sd, float avg_speed);
extern void WB_weibull_k_param_monthly(double *k_array_12);
extern void WB_weibull_k_param_by_sd_and_avg(double *p_array_sd, double *p_array_avg, int length, double *p_array_result);
extern double weibull_c_param(float avg_speed, double k);
extern void WB_weibull_c_param_monthly(double *p_array_avg_speed, double *p_array_k_param, int length, double *p_array_result);
//
extern void wind_direction_frequencies(int *p_direction,int data_count, int *p_frequency);
extern void wind_direction_frequencies_print(int *p_direction,int data_count);
//
///----------------------------------------------------------------------------------------------------------------------------------------
///Lambert Persistance  Routines
///----------------------------------------------------------------------------------------------------------------------------------------
extern double lambert_persistance_value(float *p_speed,int *p_direction,int length);
extern void lambert_persistant_value_hourly(float *p_speed,int *p_direction,int length, float *p_persistant_values);
extern void lambert_persistant_value_monthly(char *pData, int buffer_size, float *p_speed,int *p_direction,int length, float *p_persistant_values);
extern void lambert_persistant_value_seasonal(char *pData, int buffer_size, float *p_speed,int *p_direction,int length, float *p_persistant_values);
